﻿using Engine;
using Game;
using Mekiasm.Common;
using static Mekiasm.MekCraftingRecipe;
namespace Mekiasm
{
    public class ElectricDrink : ComplexModelItem
    {
        public static int Index;
        public ElectricDrink() : base(new ModelItem[] {
            new ModelItem("Blade", "mixer"), new ModelItem("GlassHandle1", "mixer"),
            new ModelItem("GlassHandle3", "mixer"), new ModelItem("GlassHandle2", "mixer"),
            new ModelItem("BladeHolder", "mixer"), new ModelItem("Spout", "mixer"),
            new ModelItem("GlassLid", "mixer"), new ModelItem("GlassTop", "mixer"),
            new ModelItem("GlassWest", "mixer"), new ModelItem("GlassSouth", "mixer"),
            new ModelItem("GlassEast", "mixer"), new ModelItem("GlassNorth", "mixer"),
            new ModelItem("GlassBase", "mixer"), new ModelItem("Base2", "mixer"),
            new ModelItem("Base1", "mixer")
        }, "mixer", "饮料制作机")
        {
            
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            return false;
        }
        public override bool OnInteract(SubsystemBlockBehavior blockBehavior, TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            ComponentElectricDrink mcomponent = blockBehavior.Project.FindSubsystem<SubsystemBlockEntities>().GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z).Entity.FindComponent<ComponentElectricDrink>(true);
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new ElectricFoodMachineWidget(mcomponent, componentMiner);
            return true;
        }
        public override void OnBlockAdded(SubsystemBlockBehavior blockBehavior, int value, int oldValue, int x, int y, int z)
        {
            ILibrary.AddBaseEnergyEntity(DisplayName, x, y, z, null,
                ILibrary.GetRotetedConfig(value, new MachineFaceConfig[] {
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.OUT,MekBlock.DeviceType.Item),
            new MachineFaceConfig(MekBlock.MachineMode.OUT,MekBlock.DeviceType.Item)
            }));
            ElectricSystem.Add(new ElectricDrinkElement(x, y, z));
        }
        public override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
        {
            ElectricSystem.Add(new ElectricDrinkElement(x, y, z));
        }
        public override void OnBlockRemoved(SubsystemBlockBehavior blockBehavior, int value, int newValue, int x, int y, int z)
        {
            ILibrary.RemoveBlockEntity(x, y, z);
            ElectricSystem.Remove(new Point3(x, y, z));
        }

        public override MekBlock.DeviceType GetDeviceType()
        {
            return MekBlock.DeviceType.Electric;
        }

    }
}
